<?php
//dezend by http://www.yunlu99.com/ QQ:270656184
defined('BASEPATH') || exit('No direct script access allowed');

if (!function_exists('byte_format')) {
	function byte_format($num, $precision = 1)
	{
		$CI = &get_instance();
		$CI->lang->load('number');

		if (1000000000000 <= $num) {
			$num = round($num / 1099511627776, $precision);
			$unit = $CI->lang->line('terabyte_abbr');
		}
		else if (1000000000 <= $num) {
			$num = round($num / 1073741824, $precision);
			$unit = $CI->lang->line('gigabyte_abbr');
		}
		else if (1000000 <= $num) {
			$num = round($num / 1048576, $precision);
			$unit = $CI->lang->line('megabyte_abbr');
		}
		else if (1000 <= $num) {
			$num = round($num / 1024, $precision);
			$unit = $CI->lang->line('kilobyte_abbr');
		}
		else {
			$unit = $CI->lang->line('bytes');
			return number_format($num) . ' ' . $unit;
		}

		return number_format($num, $precision) . ' ' . $unit;
	}
}

?>
